/**
 *  Copyright 2013 University Pierre & Marie Curie - UMR CNRS 7606 (LIP6/MoVe)
 *  All rights reserved.   This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  Initial contributor:
 *    Jean-Luc Amitousa - Thanh Cong - <jeanluc.amitousa.mankoy@gmail.com>
 *
 *  Mailing list:
 *    lom-messan.hillah@lip6.fr
 */
package sdmakerz_v1.coresyntax.menu;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import sdmakerz_v1.coresyntax.SDMakerV1Utils;
import sdmakerz_v1.coresyntax.io.SDMakerIO;

public class SDMakerV1GeneralSettingsFrame 
extends JFrame
implements ActionListener {
	JTextField rootDirNameForInputTF;
	
	JButton okButton, cancelButton, restoreRootDirNameForInputButton;
	
	public SDMakerV1GeneralSettingsFrame(){
		JPanel panel= new JPanel();
		JLabel rootDirNameForInputPrompt= new JLabel("imports root dir: ");
		
		okButton= new JButton("OK");
		cancelButton= new JButton("CANCEL");
		restoreRootDirNameForInputButton= new JButton("RESTORE");
		
		rootDirNameForInputTF= new JTextField(
				SDMakerIO.getRootDirNameForInput(), 20);
		
		setTitle("sdmaker settings");
		setSize(new Dimension(500, 90));
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		
		panel.add(rootDirNameForInputPrompt);
		panel.add(rootDirNameForInputTF);
		panel.add(restoreRootDirNameForInputButton);
		
		panel.add(okButton);
		panel.add(cancelButton);
		add(panel);
		
		restoreRootDirNameForInputButton.addActionListener(this);
		okButton.addActionListener(this);
		cancelButton.addActionListener(this);
	}

	public void actionPerformed(ActionEvent e) {
		Object pressed= e.getSource();
		
		if(pressed==okButton){
			SDMakerIO.changeRootDirNameForInput(
					rootDirNameForInputTF.getText());
		}
		else if(pressed==restoreRootDirNameForInputButton){
			rootDirNameForInputTF.setText(SDMakerIO.getRootDirNameForInput());
			rootDirNameForInputTF.setCaretPosition(0);
		}
		
		if(pressed==okButton||pressed==cancelButton){
			dispose();
		}
	}
}

